<template>
	<sw-common-frame :loading="loading">
		<template slot="query">
			<el-form size="small" :inline="true" @submit.stop>
				<el-form-item>
					<el-input placeholder="请输入用户账号" v-model="queryData.account" clearable></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" @click="queryTableData()">搜索</el-button>
				</el-form-item>
			</el-form>
		</template>
		<template slot="table">
			<el-table size="medium" :data="tableData" stripe height="100%">
				<el-table-column prop="account" label="用户账号"></el-table-column>
				<el-table-column prop="frozenTime" label="冻结开始时间"></el-table-column>
				<el-table-column prop="createName" label="冻结时长">
					<template slot-scope="{ row }">{{ row.frozenLen }}秒钟</template>
				</el-table-column>
				<el-table-column prop="content" label="当前状态">
					<template slot-scope="{ row }">
						<el-tag size="medium" v-if="row.isFrozen === '1'" type="danger">锁定</el-tag>
						<el-tag size="medium" v-if="row.isFrozen === '2'" type="success">正常</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" width="90">
					<template slot-scope="{ row }">
						<el-button size="medium" type="text" @click="handleRemoveFrozen(row)">{{ row.isFrozen === '1' ? '解除冻结' : '冻结账号' }}</el-button>
					</template>
				</el-table-column>
			</el-table>
		</template>
		<template slot="page">
			<sw-pagination :total="dataCount" :page.sync="queryData.page" :limit.sync="queryData.limit" @change="queryTableData()"></sw-pagination>
		</template>
	</sw-common-frame>
</template>

<script>
import listMixins from '@/mixins/listMixins';
import { getFrozenRecordList, updateFrozenRecord } from '@/api/system/tbFrozenRecord';
export default {
	mixins: [listMixins],
	data() {
		return {};
	},
	computed: {
		listFunction() {
			return eval(getFrozenRecordList);
		}
	},
	methods: {
		//解除冻结数据
		handleRemoveFrozen(data) {
			let that = this;
			this.$confirm(`此操作将解除用户<font color="#f00">【${data.userName}】</font>的锁定, 是否继续?`, '删除提示', {
				type: 'warning',
				dangerouslyUseHTMLString: true,
				async beforeClose(action, instance, done) {
					if (action === 'confirm') {
						instance.confirmButtonLoading = true;
						await that.updateUserForzenStatus(data);
						instance.confirmButtonLoading = false;
						done();
					} else {
						done();
					}
				}
			}).catch(() => {});
		},

		//修改用户账号冻结状态
		async updateUserForzenStatus(data) {
			let frozenStatus = data.isFrozen === '1' ? '2' : '1';
			let params = { id: data.id, isFrozen: data.isFrozen === '1' ? '2' : '1' };
			let result = await updateFrozenRecord(params).then((res) => res.data);
			if (result.code === '0') {
				data.isFrozen = frozenStatus;
				this.$message.success('解除用户冻结成功');
			}
		}
	}
};
</script>
